package com.hualude.roadsign.controller;

import com.hualude.roadsign.dto.*;
import com.hualude.roadsign.service.RuleGroupService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

@Controller
@RequestMapping("/rds_ruleGroup")
public class RuleGroupController {

    @Resource
    RuleGroupService ruleGroupService;

    @ResponseBody
    @RequestMapping("/getRuleGroup4DT")
    public DTResponseDto getRuleGroup4DT(DTRequestDto dtRequestDto, String orgIds,String content,String time){
        DTResponseDto dtResponseDto=new DTResponseDto();
        try {
            dtResponseDto=ruleGroupService.getRuleGroup4DT(dtRequestDto,orgIds,content,time);
        }catch (Exception e){
            e.printStackTrace();
        }
        return dtResponseDto;
    }


    @ResponseBody
    @RequestMapping("/modifyRuleGroup")
    public JsonMsgDto modifyRuleGroup(RuleGroupDto ruleGroupDto){
        JsonMsgDto jsonMsgDto=new JsonMsgDto();
        try{
            jsonMsgDto.setIsSuccess(true);
            jsonMsgDto.setJsonData(ruleGroupService.modifyRuleGroup(ruleGroupDto));
        }catch (Exception e){
            jsonMsgDto.setIsSuccess(false);
            e.printStackTrace();
        }
        return jsonMsgDto;
    }

    @ResponseBody
    @RequestMapping("/deleteRuleGroupById")
    public JsonMsgDto deleteRuleGroupById(String ruleGroupId) throws Exception {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try{
            jsonMsgDto.setIsSuccess(true);
            jsonMsgDto.setJsonData(ruleGroupService.deleteRuleGroupById(ruleGroupId));
        }catch (Exception e){
            jsonMsgDto.setIsSuccess(false);
            e.printStackTrace();
        }
        return jsonMsgDto;
    }

    @ResponseBody
    @RequestMapping("/getRedRuleByModelId")
    public DTResponseDto getRedRuleByModelId(DTRequestDto dtRequestDto,Integer modelId)throws Exception{
        DTResponseDto dtResponseDto=null;
        try{
            dtResponseDto=ruleGroupService.getRedRuleByModelId(dtRequestDto,modelId);
        }catch (Exception e){
            e.printStackTrace();
        }
        return dtResponseDto;
    }

    @ResponseBody
    @RequestMapping("/getBlueRuleByModelId")
    public DTResponseDto getBlueRuleByModelId(DTRequestDto dtRequestDto,Integer modelId)throws Exception{
        DTResponseDto dtResponseDto=null;
        try{
            dtResponseDto=ruleGroupService.getBlueRuleByModelId(dtRequestDto,modelId);
        }catch (Exception e){
            e.printStackTrace();
        }
        return dtResponseDto;
    }

    @ResponseBody
    @RequestMapping("/addRedRule")
    public JsonMsgDto addRedRule(PortRedRuleDto dto)throws Exception{
        JsonMsgDto jsonMsgDto=new JsonMsgDto();
        try{
            jsonMsgDto.setIsSuccess(true);
            jsonMsgDto.setJsonData(ruleGroupService.addRedRule(dto));
        }catch (Exception e){
            jsonMsgDto.setIsSuccess(false);
            e.printStackTrace();
        }
        return jsonMsgDto;
    }

    @ResponseBody
    @RequestMapping("/addBlueRule")
    public JsonMsgDto addBlueRule(PortBlueRuleDto dto)throws Exception{
        JsonMsgDto jsonMsgDto=new JsonMsgDto();
        try{
            jsonMsgDto.setIsSuccess(true);
            jsonMsgDto.setJsonData(ruleGroupService.addBlueRule(dto));
        }catch (Exception e){
            jsonMsgDto.setIsSuccess(false);
            e.printStackTrace();
        }
        return jsonMsgDto;
    }


    @ResponseBody
    @RequestMapping("/updateModelRule")
    public JsonMsgDto updateModelRule(Integer ruleModelId)throws Exception{
        JsonMsgDto jsonMsgDto=new JsonMsgDto();
        try{
            jsonMsgDto.setIsSuccess(true);
            jsonMsgDto.setJsonData(ruleGroupService.updateModelRule(ruleModelId));
        }catch (Exception e){
            e.printStackTrace();
        }
        return jsonMsgDto;
    }

    @ResponseBody
    @RequestMapping("/updateRedRule")
    public JsonMsgDto updateRedRule(PortRedRuleDto redRuleDto){
        JsonMsgDto jsonMsgDto=new JsonMsgDto();
        try{
            jsonMsgDto.setIsSuccess(true);
            jsonMsgDto.setJsonData(ruleGroupService.updateRedRule(redRuleDto));
        }catch (Exception e){
            jsonMsgDto.setIsSuccess(false);
            e.printStackTrace();
        }
        return jsonMsgDto;
    }
    @ResponseBody
    @RequestMapping("/updateBlueRule")
    public JsonMsgDto updateBlueRule(PortBlueRuleDto blueRuleDto){
        JsonMsgDto jsonMsgDto=new JsonMsgDto();
        try{
            jsonMsgDto.setIsSuccess(true);
            jsonMsgDto.setJsonData(ruleGroupService.updateBlueRule(blueRuleDto));
        }catch (Exception e){
            jsonMsgDto.setIsSuccess(false);
            e.printStackTrace();
        }
        return jsonMsgDto;
    }

}
